/**********************************************
 * 
 * File Name				:	SysLogInfoServiceImpl.java
 * 
 * Last Changed Date		: 	$Date: 2009-08-06 14:51:00 +0800 (星期四, 06 八月 2009) $
 * 
 * Last Changed Revision	:	$Revision: 92 $
 * 
 * Last Changed Author		:	$Author: cfanboy $
 * 
 * File Header URL			:	$HeadURL: svn://www.svnhost.cn/Busi-Building/code/branch/src/com/busibuilding/administrate/security/services/SysLogInfoServiceImpl.java $
 * 
 * ********************************************
 */

package com.busibuilding.administrate.security.services;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.transaction.annotation.Transactional;

import com.busibuilding.administrate.security.dao.SysLogInfoDAO;
import com.busibuilding.administrate.security.vo.LogInfoCVO;
import com.busibuilding.common.exceptions.DAOException;
import com.busibuilding.common.exceptions.ServiceException;
import com.busibuilding.common.services.CommonServicesImpl;
import com.busibuilding.common.vo.ICommonVO;

/**
 * Class Name: SysLogInfoServiceImpl.java
 * Description: 
 * @author YU Zhipeng
 * @version 1.0
 * @since 1.0
 * Date: 2009-7-20
 */
@Transactional(rollbackForClassName={"Exception"})
public class SysLogInfoServiceImpl extends CommonServicesImpl implements
		SysLogInfoService {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 5447778526451153370L;
	
	private static Logger logger = LogManager.getLogger(SysLogInfoServiceImpl.class);
	
	private SysLogInfoDAO dao;
	
	
	public void setDao(SysLogInfoDAO dao) {
		this.dao = dao;
	}

	@Override
	public int deleteSysteLog(ICommonVO vo) throws ServiceException {
		int id = SQLMAP_COMMON_RESULT_ERROR;
		try {
			id = dao.delete(vo);
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_DELETE_SYSTEM_LOG, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_DELETE_SYSTEM_LOG, e);
		}
		return id;
	}

	@Override
	public int logSystemLog(ICommonVO vo) throws ServiceException {
		int id = SQLMAP_COMMON_RESULT_ERROR;
		try {
			id = dao.insert(vo);
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_LOG_SYSTEM_LOG, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_LOG_SYSTEM_LOG, e);
		}
		return id;
	}

	@Override
	public List<LogInfoCVO> searchSystemLogByCondition(ICommonVO vo)
			throws ServiceException {
		List<LogInfoCVO> resultList = new ArrayList<LogInfoCVO>();
		try {
			resultList = dao.searchSystemLogByCondition(vo);
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_SEARCH_SYSTEM_LOG, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_SEARCH_SYSTEM_LOG, e);
		}
		return resultList;
	}

	@Override
	public List<LogInfoCVO> searchSystemLogByCondition(ICommonVO vo, int skipResults,
			int maxResults) throws ServiceException {
		List<LogInfoCVO> resultList = new ArrayList<LogInfoCVO>();
		try {
			resultList = dao.searchSystemLogByCondition(vo, skipResults, maxResults);
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_SEARCH_SYSTEM_LOG, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_SEARCH_SYSTEM_LOG, e);
		}
		return resultList;
	}

	@Override
	public List<LogInfoCVO> searchSystemLogs() throws ServiceException {
		List<LogInfoCVO> resultList = new ArrayList<LogInfoCVO>();
		try {
			resultList = dao.searchSystemLogs();
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_SEARCH_SYSTEM_LOG, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_SEARCH_SYSTEM_LOG, e);
		}
		return resultList;
	}

	@Override
	public List<LogInfoCVO> searchSystemLogs(int skipResults, int maxResults) throws ServiceException{
		List<LogInfoCVO> resultList = new ArrayList<LogInfoCVO>();
		try {
			resultList = dao.searchSystemLogs(skipResults, maxResults);
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_SEARCH_SYSTEM_LOG, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_SEARCH_SYSTEM_LOG, e);
		}
		return resultList;
	}

	@Override
	public int updateSysteLog(ICommonVO vo) throws ServiceException {
		int id = SQLMAP_COMMON_RESULT_ERROR;
		try {
			id = dao.update(vo);
		} catch (DAOException e) {
			logger.fatal(e.getErrorCode() + ":" + e.getErrorMessage());
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_UPDATE_SYSTEM_LOG, e);
		} catch (Exception e) {
			logger.fatal(e);
			throw new ServiceException(SERVICE_ERROR_CODE_SECURITY_UPDATE_SYSTEM_LOG, e);
		}
		return id;
	}

	@Override
	public int getRecordsCount(ICommonVO vo) throws ServiceException {
		// TODO Auto-generated method stub
		return 0;
	}
	
	

}
